import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreStorageService extends BaseService<any> {
  private readonly logger = new Logger(CoreStorageService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getDefaultStorage
   * 对应 PHP: CoreStorageService_core::getDefaultStorage()
   * 逻辑类型: undefined - undefined
   */
  async getDefaultStorage(site_id: number) {
    // 基于PHP真实逻辑: getDefaultStorage
    // PHP原文: $storage_list = $this->getStorageConfigList($site_id);         foreach($storage_list as $k => $v){             if($v['is_use'] == StorageDict::ON){   ...
const storage_list = this.getStorageConfigList(site_id);
        foreach(storage_list as k => v){
            if (v.is_use == StorageDict.ON) {
                const item_storage = v.params || [];
                item_storage.storage_type = v.storage_type;
                return item_storage;
            }
  }

  /**
   * getStorageByType
   * 对应 PHP: CoreStorageService_core::getStorageByType()
   * 逻辑类型: undefined - undefined
   */
  async getStorageByType(site_id: number, type: number) {
    // 基于PHP真实逻辑: getStorageByType
    // PHP原文: $storage_list = $this->getStorageConfigList($site_id);         foreach($storage_list as $k => $v){             if($v['storage_type'] == $type){       ...
const storage_list = this.getStorageConfigList(site_id);
        foreach(storage_list as k => v){
            if (v.storage_type == type) {
                const item_storage = v.params || [];
                item_storage.storage_type = v.storage_type;
                return item_storage;
            }
  }

  /**
   * getStorageConfig
   * 对应 PHP: CoreStorageService_core::getStorageConfig()
   * 逻辑类型: undefined - undefined
   */
  async getStorageConfig(site_id: number) {
    // 基于PHP真实逻辑: getStorageConfig
    // PHP原文: $info = (new CoreConfigService())->getConfig($site_id, 'STORAGE')['value'] ?? [];         if(empty($info))             $info = ['default' => StorageDi...
const info = this.coreConfigService.getConfig(site_id, 'STORAGE').value || [];
        if(!info))
            const info = [default: StorageDict.LOCAL];

        return info;


    }

    /**
     * 获取云存储列表
     * @param int site_id
     * @return */
    async getStorageList(int site_id = 0)
    {
        const config_type = this.getStorageConfig(site_id];
        const storage_type_list = StorageDict.getType(];
        const list = [);
        foreach (storage_type_list as k => v) {
            const data = [];
            data.storage_type = k;
            data.is_use = k == config_type.default ? StorageDict.ON : StorageDict.OFF;
            data.name = v.name;
            data.component = v.component;
            foreach (v.params as k_param => v_param) {
                data.params[k_param] = [
                    name: v_param,
                    value: config_type[k][k_param] || ''
                ];
            }
            list[] = data;
  }

  /**
   * getStorageList
   * 对应 PHP: CoreStorageService_core::getStorageList()
   * 逻辑类型: undefined - undefined
   */
  async getStorageList(site_id: number) {
    // 基于PHP真实逻辑: getStorageList
    // PHP原文: $config_type = $this->getStorageConfig($site_id);         $storage_type_list = StorageDict::getType();         $list = [];         foreach ($storage_t...
const config_type = this.getStorageConfig(site_id];
        const storage_type_list = StorageDict.getType(];
        const list = [);
        foreach (storage_type_list as k => v) {
            const data = [];
            data.storage_type = k;
            data.is_use = k == config_type.default ? StorageDict.ON : StorageDict.OFF;
            data.name = v.name;
            data.component = v.component;
            foreach (v.params as k_param => v_param) {
                data.params[k_param] = [
                    name: v_param,
                    value: config_type[k][k_param] || ''
                ];
            }
            list[] = data;
  }

  /**
   * getStorageConfigList
   * 对应 PHP: CoreStorageService_core::getStorageConfigList()
   * 逻辑类型: undefined - undefined
   */
  async getStorageConfigList(site_id: number) {
    // 基于PHP真实逻辑: getStorageConfigList
    // PHP原文: $config_type = $this->getStorageConfig($site_id);         $storage_type_list = StorageDict::getType();         $list = [];         foreach ($storage_t...
const config_type = this.getStorageConfig(site_id];
        const storage_type_list = StorageDict.getType(];
        const list = [);
        foreach (storage_type_list as k => v) {
            const data = [];
            data.storage_type = k;
            data.is_use = k == config_type.default ? StorageDict.ON : StorageDict.OFF;
            data.name = v.name;
            foreach (v.params as k_param => v_param) {
                data.params[k_param] = config_type[k][k_param] || '';
            }
            list[] = data;
  }
}
